﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProxyWrapper.UserProxy;
using System.Data;
using System.Web.Services.Protocols;
namespace ProxyWrapper
{
    public class UserServiceWrapper
    {
        UserServiceSoapClient _client = null;
        public UserDetails ValidateLogin(string userName, string password)
        {
            _client = new UserServiceSoapClient();
            return _client.ValidateUser(userName, password,"","");
        }
        public string AddUser(string email, string appuserName, string password, string company)
        {
            _client = new UserServiceSoapClient();
            return _client.AddUser(0, email, appuserName, password, company, 0, 0, null, null);
        }
        public string AddAppUser(int userId,string email, string appuserName, string password, string company, int deviceLimit, int clientId, List<string> authorizedServiceList,string hashcode)
        {
            _client = new UserServiceSoapClient();
            return _client.AddUser(userId, email, appuserName, password, company, deviceLimit, clientId, authorizedServiceList != null ? authorizedServiceList.ToArray() : null, hashcode);
        }
        public List<UserDetails> GetUserList(int clientId,string hashCode)
        {
            _client = new UserServiceSoapClient();
            UserDetails[] _dtails = _client.ListUsers(clientId, hashCode);
            if (_dtails != null)
                return _dtails.ToList<UserDetails>();
            else
                return new List<UserDetails>();
        }
        public string DeleteUser(int userId, int clientId, string hashCode)
        {
            _client = new UserServiceSoapClient();
            return _client.DeleteUser(userId, clientId, hashCode);
        }
        public string UpdateUser(int userId,string appUserName,string password,int deviceLimit,List<string> lstServices,int clientId,string hashCode)
        {
            _client = new UserServiceSoapClient();
            return _client.UpdateUser(userId, appUserName, password, deviceLimit, lstServices.ToArray(), clientId, hashCode);
        }

        public string ArchiveData()
        {
            return new UserServiceSoapClient().ArchiveDataAndSendMail();
        }

        public UserDetails GetAppUser(int userId, int clientId, string hashCode)
        {
            _client = new UserServiceSoapClient();
            return _client.GetAppUser(userId, clientId, hashCode);
       
        }

        public System.Data.DataSet GetUsers(int userId, string hashCode)
        {
            _client = new UserServiceSoapClient();
            
            return _client.GetUsers(userId,hashCode);
        }

        public void AssociateServiceToUsers(UserDetails UserDetails, int ServiceId, string usersList)
        {
            _client = new UserServiceSoapClient();
            _client.AssociateServiceToUsers(UserDetails.UserId, UserDetails.HashCode, ServiceId, usersList);
        }

        public DataSet GetDevices(int clientId,string hashCode)
        {
            return new UserServiceSoapClient().GetDevices(clientId, hashCode);
        }
        public DataSet GetServicesList(int clientId, string hashCode)
        {
            return new UserServiceSoapClient().GetServicesList(clientId, hashCode);
        }
        public DataSet GetUsersList(int clientId, string hashCode)
        {
            return new UserServiceSoapClient().GetAppUsers(clientId, hashCode);
        }
        
        public string ActivateUser(int userId,string hashCode)
        {
            return new UserServiceSoapClient().ActivateUser(userId, hashCode);
        }

        public string GetSecurity(string email,string type)
        {
            return new UserServiceSoapClient().UserSecurity(email, type);
        }

        public String GetEmail(string token)
        {
            return new UserServiceSoapClient().GetEmail(token);
        }

        public string ResetPassword(string token,string password)
        {
            try
            {
                return new UserServiceSoapClient().ResetPassword(token, password);
            } catch(SoapException soapEx)
            {
                throw new Exception(soapEx.Message);
            }
        }

        public DataSet GetAccountUsers(string roleId)
        {
            return new UserServiceSoapClient().GetAccountUsers(roleId);
        }
        public  string UpdateAccounts(UserDetails objUser)
        {
            return new UserServiceSoapClient().UpdateUserAccount(objUser);
        }
        public string DeleteUserAccount(string username,string password,int userId,string hashCode)
        {
            return new UserServiceSoapClient().DeleteUserAccount(username, password, userId, hashCode);
        }

        public void ChangePassword(int userId, string newpassword, string hashCode)
        {
            new UserServiceSoapClient().ChangePassword(userId, newpassword, hashCode);
        }
        public string RegisterUser(UserDetails objUser)
        {
            return new UserServiceSoapClient().RegisterUser(objUser);
        }

        public DataSet GetAccountsDevices(int clientId,string hashCode)
        {
            return new UserServiceSoapClient().GetAccountsDevices(clientId, hashCode);
        }

        public DataSet GetComments(int userId)
        {
            return new UserServiceSoapClient().GetComments(userId);
        }
        public string AddComments(int commentId,int userId,int UserCommentedId,string commentDesc)
        {
            return new UserServiceSoapClient().AddComment(commentId, UserCommentedId, commentDesc, userId);
        }
        public string DeleteComments(int commentId)
        {
            return new UserServiceSoapClient().DeleteComment(commentId);
        }
        public string AddEMailIds(string userId,string loggedinuser,string emailids)
        {
            return new UserServiceSoapClient().AddEmailIds(userId, loggedinuser, emailids, "");
        }
        public string GetEmailIds(string userId)
        {
            return new UserServiceSoapClient().GetEmailIds(userId);
        }
    }
   
}
